package com.cnb.telepathytalk;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

public class HelpActivity extends DefaultActivity {
	private ViewPager pager;

	private int[] imageResIds;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_help);
		((TextView) findViewById(R.id.titlebarText)).setText(R.string.title_helper);

		imageResIds = new int[5];
		imageResIds[0] = R.drawable.addfile;
		imageResIds[1] = R.drawable.bg_intro;
		imageResIds[2] = R.drawable.bg_tab_02;
		imageResIds[3] = R.drawable.bg_titlebar;
		imageResIds[4] = R.drawable.btn_checkbox;

		pager = (ViewPager) findViewById(R.id.pager);
		pager.setAdapter(new HelperPagerAdapter(getSupportFragmentManager()));
	}

	private class HelperPagerAdapter extends FragmentPagerAdapter {
		public HelperPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int arg0) {
			ImageFragment fragment = new ImageFragment();
			fragment.resId = imageResIds[arg0];
			return fragment;
		}

		@Override
		public int getCount() {
			return imageResIds.length;
		}
	}

	static public class ImageFragment extends Fragment {
		private Context mContext;
		int resId;

		@Override
		public void onAttach(Activity activity) {
			super.onAttach(activity);
			mContext = activity;
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			ImageView view = new ImageView(mContext);
			view.setScaleType(ScaleType.CENTER_INSIDE);
			view.setImageResource(resId);
			return view;
		}
	}
}